CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/share/projects/[project_id].tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
Page for a given project.
8
Show all the public paths in a given project, and maybe other information about the project?
9
*/
10
11
import { join } from "path";
12
import basePath from "lib/base-path";
13
import { isUUID } from "lib/share/util";
14
import withCustomize from "lib/with-customize";
15
import getProject from "lib/share/get-project";
16
import getProjectInfo from "lib/project/info";
17
import getProjectOwner from "lib/project/get-owner";
18
import getOwnerName from "lib/owner/get-name";
19
import Project from "components/project/project";
20
21
export default Project;
22
23
export async function getServerSideProps(context) {
24
const { project_id } = context.params;
25
if (!isUUID(project_id)) {
26
return { notFound: true };
27
}
28
let props;
29
try {
30
const project = await getProject(project_id, [
31
"name",
32
"title",
33
"description",
34
"avatar_image_full",
35
]);
36
if (project.name) {
37
// This project probably has a nice vanity name. Possibly redirect to that instead.
38
const owner_id = await getProjectOwner(project_id);
39
const owner = await getOwnerName(owner_id);
40
if (owner) {
41
return { props: { redirect: join(basePath, owner, project.name) } };
42
}
43
}
44
props = {
45
project_id,
46
...(await getProjectInfo(project_id, context.req)),
47
...project,
48
};
49
} catch (_err) {
50
// console.warn(_err)
51
return { notFound: true };
52
}
53
54
return await withCustomize({ context, props });
55
}
56
57